import { createBrowserRouter, Navigate } from 'react-router-dom';
import React from 'react';
// import CacheRoute, { CacheSwitch } from 'react-router-cache-route'

//路由守卫
const AuthComponent = props => {
    const Com = props.children.type
    let token = sessionStorage.getItem('token')
    if (token) {
        return <Com />
    } else {
        return <Navigate to='/login'></Navigate>
    }
}


const App = React.lazy(() => import('../App'))

//李伟业
const Login = React.lazy(() => import('../components/Login/Login'))
const Login2 = React.lazy(() => import('../components/Login/Login2'))
const ReaderNews = React.lazy(() => import('../components/Login/ReaderNew'))
const Yzm = React.lazy(() => import('../components/Login/Yzm'))
const Rldl = React.lazy(() => import('../components/Login/Rldl'))
//苗珺朔
const Home = React.lazy(() => import('../components/Home/Home'))
const Zhuanti = React.lazy(() => import('../components/Home/Zhuanti'))
const Context = React.lazy(() => import('../components/Home/Context'))
const Zhifu = React.lazy(() => import('../components/Home/Zhifu'))
const Search = React.lazy(() => import('../components/Home/Search'))
const Zhuanxiang = React.lazy(() => import('../components/Home/Zhuanxiang'))
//李博聪
const Dynamic = React.lazy(() => import('../components/Dynamic/Dynamic'))

//庞子腾
const Talk = React.lazy(() => import('../components/Talk/Talk'))
const Message = React.lazy(() => import('../components/Talk/component/Message'))
const Like = React.lazy(() => import('../components/Talk/component/Like'))
const Comment = React.lazy(() => import('../components/Talk/component/Comment'))
const Fans = React.lazy(() => import('../components/Talk/component/Fans'))
const Notice = React.lazy(() => import('../components/Talk/component/Notice'))
const Chat = React.lazy(() => import('../components/Talk/component/Chat'))
// 设置
const Setting = React.lazy(() => import('../components/Talk/Setting'))
const SetList = React.lazy(() => import('../components/Talk/setting/SetList'))
const About = React.lazy(() => import('../components/Talk/setting/About'))
const Appreciate = React.lazy(() => import('../components/Talk/setting/Appreciate'))
const Push = React.lazy(() => import('../components/Talk/setting/Push'))
const Secure = React.lazy(() => import('../components/Talk/setting/Secure'))
const Information = React.lazy(() => import('../components/Talk/setting/Information'))
const Up_phone=React.lazy(()=>import('../components/Talk/setting/Up_phone'))
const Up_password=React.lazy(()=>import('../components/Talk/setting/Up_password'))
//王晓行
const My = React.lazy(() => import('../components/My/My'))
const Homes = React.lazy(() => import('../components/My/Homes'))



const router = createBrowserRouter(
    [
        {
            path: '/app',
            element: <App></App>,
            children: [
                {
                    path: '/app/home',
                    element: <Home></Home>,
                },
                {
                    path: '/app',
                    element: <Navigate to='/app/home'></Navigate>
                },
                {
                    path: '/app/home',
                    element: <Home></Home>,
                },
                {
                    path: '/app/dynamic',
                    element: <AuthComponent><Dynamic></Dynamic></AuthComponent>,
                },
                {
                    path: '/app/talk',
                    element: <AuthComponent><Talk></Talk></AuthComponent>,
                    path: '/app/dynamic',
                    element: <AuthComponent><Dynamic></Dynamic></AuthComponent>,
                },
                {
                    path: '/app/talk',
                    element: <AuthComponent><Talk></Talk></AuthComponent>,
                    children: [
                        {
                            path: '/app/talk/message',
                            element: <Message></Message>
                        },
                        {
                            path: '/app/talk',
                            element: <Navigate to='/app/talk/message'></Navigate>
                        },
                        {
                            path: '/app/talk/like',
                            element: <Like></Like>
                        },
                        {
                            path: '/app/talk/comment',
                            element: <Comment></Comment>
                        },
                        {
                            path: '/app/talk/fans',
                            element: <Fans></Fans>
                        },
                        {
                            path: '/app/talk/notice',
                            element: <Notice></Notice>
                        },
                        {
                            path: '/app/talk/chat',
                            element: <Chat></Chat>
                        }
                    ]
                },
                {
                    path: '/app/setting',
                    element: <Setting />,
                    children: [
                        {
                            path: '/app/setting/setlist',
                            element: <SetList />
                        },
                        {
                            path: '/app/setting',
                            element: <Navigate to='/app/setting/setlist' />
                        },
                        {
                            path: '/app/setting/about',
                            element: <About />
                        },
                        {
                            path: '/app/setting/appreciate',
                            element: <Appreciate />
                        },
                        {
                            path: '/app/setting/push',
                            element: <Push />
                        },
                        {
                            path: '/app/setting/secure',
                            element: <Secure />
                        },
                        {
                            path: '/app/setting/information',
                            element: <Information />
                        },
                        {
                            path:'/app/setting/up_phone',
                            element:<Up_phone/>
                        },
                        {
                            path:'/app/setting/up_password',
                            element:<Up_password/>
                        }
                    ]
                },
                {
                    path: '/app/my',
                    element: <AuthComponent><My></My></AuthComponent>,
                }
            ]
        },
        {
            path: '/homes',
            element: <AuthComponent><Homes></Homes></AuthComponent>,
        },
        {
            path: '/',
            element: <Navigate to='/reader'></Navigate>
        },
        {
            path: '/login',
            element: <Login></Login>,
        },
        {
            path: '/zhuanti',
            element: <AuthComponent><Zhuanti></Zhuanti></AuthComponent>
        },
        {
            path: "/context",
            element: <AuthComponent><Context></Context></AuthComponent>
        },
        {
            path: "/search",
            element: <AuthComponent><Search></Search></AuthComponent>
        },
        {
            path: "/zhuanxiang",
            element: <AuthComponent><Zhuanxiang></Zhuanxiang></AuthComponent>
        },
        {
            path: "/zhifu",
            element: <AuthComponent><Zhifu></Zhifu></AuthComponent>

        },
        {
            path: '/login2',
            element: <Login2></Login2>,

        },
        {
            path: '/reader',
            element: <ReaderNews></ReaderNews>,
        },
        {
            path: '/yzm',
            element: <Yzm></Yzm>,
        }, {
            path: '/rldl',
            element: <Rldl></Rldl>,
        }

    ]
)

export default router